namespace fnInit {

    // 混合类型的接口
    interface Count {
        interval: number //属性
        reset(): void  //方法
        (start: number): string//函数
    }


    function MakeCount(): Count {
        let obj = ((st: number) => {
            return ''
        }) as Count
        obj.interval = 5
        obj.reset = () => {
        }
        return obj

    }

// 使用
    const c = MakeCount();
    console.log(c(10));        // 调用函数部分
    console.log(c.interval);   // 访问属性
    c.reset();                 // 调用方法


    interface ISum {

        //   ✅ 1. 接口定义函数类型（常见写法）
        //   interface MyFunc {
        //   (x: number, y: number): number;
        // }
        // const add: MyFunc = (a, b) => a + b;

        //   ✅ 2. 带属性的函数接口
        //   接口不仅可以定义函数类型，还可以为函数添加额外的属性：
        //   interface MyFunc {
        //   (msg: string): void;
        //   description: string;
        // }

        // (参数:类型):返回值类型
        (a: number | string, b: number | string): number;

        // fb:(a:number)=>void
    }

    interface HasZks {
        zzzks(a: string, b: string): void  //等价于zzzks:(a:string,b:string)=>void
    }

    function getZks<T extends HasZks>(ZKS: T) {
        return ZKS.zzzks("1", "2")
    }

    let UseZks = {
        zzzks: function (a: string, b: string) {
            console.log(a + b)
        }
    }
    getZks(UseZks)


    // 箭头函数的返回值  简单写法
    const getSum: ISum = (a, b) => {
        return (a as number) + (b as number);
    };
    console.log(getSum(6, 5));
    // 完整的写法为  ()=>返回值类型

    const getSum2: (a: string, b: number) => number | string = (
        a: string,
        b: number
    ): number | string => {
        return a + (b as number);
    };

    console.log(getSum2("4", 5));

    // 普通函数的返回值
    const getSumI: ISum = function (a, b) {
        return (a as number) + (b as number); //使用了类型断言
    };
    // 完整的写法为
    const getSumI3: (a: number | string, b: number | string) => number = function (
        a: number | string,
        b: number | string
    ): number {
        return (a as number) + (b as number); //使用了类型断言
    };

    console.log(getSumI(55, 66));

    interface SearchFunc {
        (source: string, subString: string): boolean;
    }

    let mySearch: SearchFunc = function (source, subString) {
        return source.search(subString) !== -1;
    };

    console.log(mySearch("hello world", "world"));

    function noVoid(...args: any): void {
        console.log(args);
    }

    console.log(noVoid(123, 563, 66));

    function greeter(fn: (s: string) => void) {
        fn("nihao");
    }

    greeter((pla) => {
        console.log(pla);
    });


    const add = (a: number): number => {
        return a + 1
    }
}